//只有 int， double， String， bool, null, List, 或者 Map 类型对象可以直接编码成 JSON

import 'dart:convert';

import 'package:flutter_test/flutter_test.dart';

main() {
  test("testDecode", () {
    var jsonString = '''
  [
    {"score": 40},
    {"score": 80},
    {"hello":{
      "name":"zhangsan",
       "age":3
    }}
  ]
''';

    var scores = jsonDecode(jsonString);
    assert(scores is List);
    print(scores);

    var firstScore = scores[0];
    assert(firstScore is Map);
    assert(firstScore['score'] == 40);
  });

  test("testEncode", () {
    var scores = [
      {'score': 40},
      {'score': 80},
      {'score': 100, 'overtime': true, 'special_guest': null}
    ];

    var jsonText = jsonEncode(scores);
    assert(jsonText ==
        '[{"score":40},{"score":80},'
            '{"score":100,"overtime":true,'
            '"special_guest":null}]');
  });
}
